using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;

namespace Pixysoft.Security
{
    public class MD5
    {
        public static string GetMD5(string content)
        {
            lock (typeof(MD5))
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(content, "md5");
            }
        }

        public static byte[] GetMD5(byte[] content)
        {
            lock (typeof(MD5))
            {
                return StringCoder.StringToByte(GetMD5(StringCoder.ByteToString(content)));
            }
        }

        public static bool Compare(string contentA, string contentB)
        {
            if (GetMD5(contentA).Trim().ToUpper() == GetMD5(contentB).ToUpper().Trim())
                return true;
            return false;
        }

        public static bool Compare(byte[] contentA, byte[] contentB)
        {
            return Compare(StringCoder.ByteToString(contentA), StringCoder.ByteToString(contentB));
        }

    }
}
